package com.macasa.panel.entity.impl;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.enumerations.CronType;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.AbstractModel;
import com.macasa.panel.entity.api.ICronLog;

@Entity
@Table(name = "cron_log")
@SequenceGenerator(name = "CronLog_SEQ", sequenceName = "CronLogIdSeq", initialValue = 1)
@Getter
@Setter
@ToString
public class CronLog extends AbstractModel<Integer> implements ICronLog {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= 5018496496536843862L;

	@Id
	@Column(name = "cron_lock_id", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "CronLog_SEQ")
	private Integer				id;

	@Enumerated(EnumType.STRING)
	@Column(name = "type", nullable = false)
	private CronType			type;

	@Temporal(TemporalType.DATE)
	@Column(name = "date", nullable = false)
	private Date				date;

	@Column(name = "log", nullable = false)
	private String				log;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof CronLog)) {
			return false;
		}

		final CronLog other = CastHelpers.cast(obj, CronLog.class);

		return Objects.equal(this.id, other.id) && Objects.equal(this.type, other.type) && Objects.equal(this.date, other.date)
				&& Objects.equal(this.log, other.log);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.id, this.type, this.date, this.log);
	}
}
